<template>

    <div>

        <!-- {{ registId }} -->
    </div>
    <el-row>
        <el-col :span="4"> <el-button type="primary" size="small" @click="applay">申请</el-button> </el-col>
        <el-col :span="4"> <el-button type="primary" size="small">取消</el-button> </el-col>

    </el-row>
    <el-table :data="tableData" style="width: 100%" @selection-change="selectChange" v-loading="loading">
        <el-table-column type="selection" width="180" />
        <!-- <el-table-column prop="checkId" label="checkId" width="180" /> -->
        <el-table-column prop="name" label="检查项目名称" width="180" />

        <el-table-column prop="price" label="单价" />
        <!-- <el-table-column prop="userid" label="操作">
            <template #default="scope">
            </template>
</el-table-column> -->

    </el-table>






</template>

<script setup lang="ts" name='CheckItemSelect'>
import { service } from "@/utils/request";
import { ref, reactive, onMounted } from "vue";


const loading = ref(false)


const { receive, registId } = defineProps<{
    registId: string | number | null | undefined,
    receive: (items: any[]) => void
}>()


interface InspectItem {
    checkId?: string,
    name: string,
    price: number,
    createtime?: string
}

let newSelection: any[] = [];


const tableData = ref<InspectItem[]>([]);


function loadDataList() {
    loading.value = true
    service.get<InspectItem[]>('/inspectitem/list').then((items) => {
        tableData.value = items;
        loading.value = false;
    })

}

/**
 * 监控数据行 被选中的事件
 */
function selectChange(newSelections: any[]) {
    console.log(newSelections);
    newSelection = newSelections

}


function applay() {

    service.get('/doctor/inspectApply?registId=' + registId, {
        params: {
            inspectIds: newSelection.map((item: any) => item.inspectId)
        }
    }).then(success => {
        if (success) {
            //让父组件  重新查询所有的 申请项目
            receive([]);
        }

    })


}


onMounted(() => {
    loadDataList()
})


</script>

<style scoped></style>